package com.qqtech.qquan.community.controller;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.community.enums.CommunityLocalnewsStatusDictEnum;
import com.qqtech.qquan.community.model.CommunityLocalnews;
import com.qqtech.qquan.community.model.CommunityLocalnewsQuery;
import com.qqtech.qquan.community.model.CommunityLocalnewsVo;
import com.qqtech.qquan.community.service.CommunityLocalnewsService;
import com.qqtech.web.context.BaseWebController;

@Controller
@RequestMapping(value = "/community/localnews")
public class CommunityLocalnewsController extends BaseWebController<CommunityLocalnews, CommunityLocalnewsQuery> {
	@Resource
	private CommunityLocalnewsService communityLocalnewsService;

	@Override
	protected BaseService<CommunityLocalnews> getBaseService() {
		return communityLocalnewsService;
	}

	/**
	 * 列表
	 * 
	 * @param communityLocalnewsQuery
	 * @return
	 */
	@RequestMapping(value = "/page")
	@ResponseBody
	public Result page(@RequestBody CommunityLocalnewsQuery communityLocalnewsQuery) {
		Result result = new Result();
		communityLocalnewsQuery.setStatus(CommunityLocalnewsStatusDictEnum.NORMAL.getCode());
		Pageable pageKit = new PageKit(communityLocalnewsQuery.getPage(), new PageOrder(Direction.DESC, "id"));
		Page<CommunityLocalnewsVo> page = communityLocalnewsService.queryPageList(communityLocalnewsQuery, pageKit);
		result.put("page", page);
		return result;
	}

	/**
	 * pv+1在获取详情
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/detail")
	@ResponseBody
	public Result detail(@RequestBody CommunityLocalnewsQuery communityLocalnewsQuery) {
		Result result = new Result();
		CommunityLocalnewsVo detailVo = communityLocalnewsService.handleDetail(communityLocalnewsQuery.getId());
		result.put("detailVo", detailVo);
		return result;
	}

	/**
	 * 新增
	 * 
	 * @param communityLocalnews
	 * @return
	 */
	@RequestMapping(value = "/create")
	@ResponseBody
	public Result create(@RequestBody CommunityLocalnews communityLocalnews) {
		Result result = new Result();
		communityLocalnews.setPv(0);
		communityLocalnews.setStatus(CommunityLocalnewsStatusDictEnum.NORMAL.getCode());
		communityLocalnewsService.insert(communityLocalnews);
		return result;
	}
}
